package com.tube.fiddles.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.tube.fiddles.support.domain.BaseDomain;

@Entity
@Table(name = "menu")
public class Menu extends BaseDomain implements Serializable {
    private static final long serialVersionUID = 1L;

    private String menuId;
    private String menuName;
    private String menuUrl;
    private Menu parentMenu;

    @Id
    @GeneratedValue(generator = "strategy_uuid")
    @GenericGenerator(name = "strategy_uuid", strategy = "uuid")
    @Column(name = "menu_id", unique = true, nullable = false, length = 32)
    public String getMenuId() {
        return menuId;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    @Column(name = "menu_name", nullable = false, length = 32)
    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    @Column(name = "menu_url", length = 128)
    public String getMenuUrl() {
        return menuUrl;
    }

    public void setMenuUrl(String menuUrl) {
        this.menuUrl = menuUrl;
    }

//    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
    @ManyToOne
    @JoinColumn(name = "parent_menu_id")
    public Menu getParentMenu() {
        return parentMenu;
    }

    public void setParentMenu(Menu parentMenu) {
        this.parentMenu = parentMenu;
    }

    @Override
    @Transient
    public boolean isIdSet() {
        return (this.menuId != null);
    }
}
